package com.grand.ch07;

public class ExceptionDemo {
    public static void main(String[] args) {

    }
    public static double area(double r){
        try{
            if(r <= 0){
                throw new RuntimeException(); //RunntimeException 运行异常，不会声明，不会处理异常，直接报错并停止
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        double s = Math.PI * r * r;
        return s;
    }

    public static double area2(double r){
        if( r <= 0) {
            throw new FushuException("你传了一个负数"); //报异常并传递自定义字符串
        }
        double s = Math.PI*r*r;
        return s;
    }

    public static double avg(double ...arr){
        double sum=0;
        for(double i:arr){
            if(i < 0){
                throw new FushuException("参数为负数");
            }
            sum += i;
        }
        return sum;
    }

}
